package com.yueyue.sqlite;



import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import java.util.Map;


@MapperScan("com.yueyue.sqlite.mapper")
@SpringBootApplication
public class Application  {


    @Autowired
    private JdbcTemplate jdbcTemplate;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }


    public void run(String... args) throws Exception {
        // 1、建表 DDL
//        createTable();
        // 2、插入数据
        String insertUserData = "insert into user(name,age) values ('张三',18),('李四',20)";
        jdbcTemplate.update(insertUserData);
        // 3、查询语句
        String selectUserData = "select * from user";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(selectUserData);
        for (Map<String, Object> map : list) {
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                System.out.println(entry.getKey() + "=" + entry.getValue());
            }
        }
        // 4、删除整张表
//        String dropTable = "drop table user";
//        jdbcTemplate.update(dropTable);
    }



}
